<%@ page contentType="text/html; charset=UTF-8"%>
<%@taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
	<head>
		<title><bean:message key="application.title" /></title>
		<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/index.css"></link>
		<link rel="shortcut icon" href="http://www.jackslocum.com/favicon.ico" />
		<link rel="icon" href="http://www.jackslocum.com/favicon.ico" />
		<!-- GC -->
		<style type="text/css">
	html, body {
        margin:0;
        padding:0;
        border:0 none;
        overflow:hidden;
        height:100%;
    }
	</style>
	</head>
	<%
	whf.framework.security.UserContext userContext = whf.framework.web.WebContextHolder.getWebContext(request).getUserContext();
	%>
	<body scroll="no" id="docs">
		<div id="loading-mask"
			style="width:100%;height:100%;background:#c3daf9;position:absolute;z-index:20000;left:0;top:0;">
			&#160;
		</div>
		<div id="loading">
			<div class="loading-indicator">
				<img src="<%= request.getContextPath() %>/scripts/ext-1.1/resources/images/default/grid/loading.gif"
					style="width:16px;height:16px;" align="absmiddle">
				&#160;Loading...
			</div>
		</div>
		<!-- include everything after the loading indicator -->
		<script type="text/javascript" src="<%= request.getContextPath() %>/scripts/ext-1.1/adapter/ext/ext-base.js"></script>
		<script type="text/javascript" src="<%= request.getContextPath() %>/scripts/ext-1.1/ext-all.js"></script>
		<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/scripts/ext-1.1/resources/css/ext-all.css" />

		<script type="text/javascript" src="<%= request.getContextPath() %>/index.js"></script>

		<div id="header" valign="bottom">
			<% if(userContext.isAdministrator()) { %>
			<a href="javascript:cleanCache()" style="float:right;margin-right:10px;"><font color="#FFFFFF" size="-2">清除缓存</font></a>
			<% } %>
			<a href="javascript:logout()" style="float:right;margin-right:10px;"><font color="#FFFFFF" size="-2">注销</font></a>
			<a href="<%= request.getContextPath() %>/common/security/User.do?webMethod=profile" target="main" style="float:right;margin-right:10px;"><font color="#FFFFFF" size="-2">设置</font></a>
			<script>
			function logout(){
				if(confirm("确定要退出系统吗？")){
					window.location='<%= request.getContextPath() %>/homepage/logout.jsp';
				}
			}
			</script>
			<div style="padding-top:3px;">
				ITSM Service Desktop
			</div>
		</div>

		<div id="classes">
		<div>
			<a id="welcome-link" href="<%= request.getContextPath() %>/homepage/body.jsp">欢迎'<%= userContext.getUser().getName() %>'</a>
			<div>&nbsp;&nbsp;&nbsp;&nbsp;<font size=-1><%= new java.sql.Timestamp(System.currentTimeMillis()) %></font></div>
			<%! 
			void outputMenuItems(whf.framework.ext.entity.MenuItem menuItem, HttpServletRequest request, JspWriter out, int deepth) throws Exception{
				whf.framework.security.UserContext userContext = whf.framework.web.WebContextHolder.getWebContext(request).getUserContext();
				if(!whf.framework.util.PermissionUtils.hasPermission(userContext, menuItem)) return;
				String indent = "";
				for(int i=0; i <= deepth; i++){
					indent += "\t";
				}
				if(menuItem.isLeaf()) {
					String url = menuItem.getHref();
					if(!url.startsWith("/")) url = "/" + url;
					url = request.getContextPath() + url;
					//out.println(indent + "<a href=\"" + url + "\">" + menuItem.getName() + "</a>");
					out.println(indent + "<a href=\"" + request.getContextPath() + "/common/dispatcher.jsp?id="+menuItem.getId()+"\">" + menuItem.getName() + "</a>");
				} else {
					out.println(indent + "<div class=\"pkg\">");
					out.println(indent + "\t<h3>" + menuItem.getName() + "</h3>");
					out.println(indent + "\t<div class=\"pkg-body\">");
					java.util.List<whf.framework.ext.entity.MenuItem> children = menuItem.getChildren();
					for(whf.framework.ext.entity.MenuItem child: children) {
						outputMenuItems(child, request, out, deepth + 1);
					}
					out.println(indent + "\t</div>");
					out.println(indent + "</div>");
				}
			}
			%>
			<%
			whf.framework.ext.service.MenuItemService service = whf.framework.ext.service.MenuItemServiceImp.getMenuItemService();
			java.util.List<whf.framework.ext.entity.MenuItem> menus = whf.framework.util.Utils.newArrayList();
			menus.addAll(service.find("t.parent is null and t.deployed=true order by t.sortOrder"));
			menus.addAll(service.find("t.parent is not null and t.deployed=true order by t.parent, t.sortOrder"));
			
			whf.framework.ext.helper.MenuItemHelper helper = new whf.framework.ext.helper.MenuItemHelper(userContext, menus);
			java.util.List<whf.framework.ext.entity.MenuItem> rootMenuItems = helper.getRootMenuItems();
			for(whf.framework.ext.entity.MenuItem root: rootMenuItems){
				outputMenuItems(root, request, out, 0);
			}
			%>
		</div>
		</div>

		<iframe id="main" name="main" frameborder="no"></iframe>
	</body>
	<script>
	function cleanCache() {
		window.open("/framework/common/cleanColumns.jsp", null, "width=300;height=250");
	}
	</script>
</html>
